﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BusinessLogic;

namespace DangKyOnline
{
    public partial class DuyetHoSoGhiDanh : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
                KhoiTaoGiaTriBanDau();
                gvPhieuGhiDanh.DataSource = null;
                ltMessage.Text = "Không có dữ liệu";
            }
        }

        private void KhoiTaoGiaTriBanDau()
        {
            KhoiTaoGiaTriKhoaHoc();
            KhoiTaoGiaTriHangXe();
        }

        private void KhoiTaoGiaTriHangXe()
        {
            try
            {
                DataTable dtHangXe = new DataTable();
                HangXeBL objHangXeBL = new HangXeBL();
                dtHangXe = objHangXeBL.SelectAll();
                ddlHangXe.DataSource = dtHangXe;
                ddlHangXe.DataTextField = "TenHangXe";
                ddlHangXe.DataValueField = "Khoa";
                ddlHangXe.DataBind();

            }
            catch (Exception exc)
            { 
            
            }
        }

        private void KhoiTaoGiaTriKhoaHoc()
        {
            try
            {
                DataTable dtKhoaHoc = new DataTable();
                KhoaHocBL objKhoaHocBL = new KhoaHocBL();
                dtKhoaHoc = objKhoaHocBL.SelectAll();
                ddlKhoaHoc.DataSource = dtKhoaHoc;
                ddlKhoaHoc.DataTextField = "TenKhoaHoc";
                ddlKhoaHoc.DataValueField = "Khoa";
                ddlKhoaHoc.DataBind();

            }
            catch (Exception exc)
            {

            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
           PhieuGhiDanhBL objPhieuGhiDanhBL = new PhieuGhiDanhBL();
           DataTable dt = objPhieuGhiDanhBL.ListPhieuGhiDanhDangKy();
           if (dt != null && dt.Rows.Count > 0)
           {
               DataView dv = new DataView(dt);
               dv.RowFilter = " KhoaHocID = " + ddlKhoaHoc.SelectedValue;
               dv.RowFilter = " HangXeID = " + ddlHangXe.SelectedValue;
               gvPhieuGhiDanh.DataSource = dv.ToTable();
               gvPhieuGhiDanh.DataBind();
               btnDuyet.Visible = true;
               ltMessage.Text = "";
           }
           else
           {
               btnDuyet.Visible = false;
               ltMessage.Text = "Không có dữ liệu";
           }
          
        }

        public string ChangeTrangThaiGhiDanh(int intTrangThaiGhiDanh)
        {
            string strTrangThai = "";
            if (intTrangThaiGhiDanh == 1)
                strTrangThai =  "Đăng ký";
            else if (intTrangThaiGhiDanh == 2)
                strTrangThai = "Duyệt";
            else if (intTrangThaiGhiDanh == 3)
                strTrangThai = "Đã thu tiền";
            else if (intTrangThaiGhiDanh == 4)
                strTrangThai = "Hoàn tầt";
            else if (intTrangThaiGhiDanh == 5)
                strTrangThai = "Huỷ";
            return strTrangThai;
        }

        public string ChangeTrangThaiGuiMail(int intTrangThaiGuiMail)
        {
            string strTrangThai = "";
            if (intTrangThaiGuiMail == 1)
                strTrangThai = "Có";
            else if (intTrangThaiGuiMail ==0)
                strTrangThai = "Không";

            return strTrangThai;

        }

        protected void gvPhieuGhiDanh_RowDataBound(object sender, GridViewRowEventArgs e)
        {
           
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes["onmouseover"] = "javascript:ToggleRowColor(this);";
                e.Row.Attributes["onmouseout"] = "javascript:ToggleRowColor(this);";
                e.Row.Style.Add("Cursor", "Arrow");
            }
        }
    }
}